package algorithm.offer;

import java.util.Stack;

public class Offer31 {

  public static void main(String[] args) {
    int[] pushed = {1,0};
    int[] popped = {1,0};

    boolean b = validateStackSequences(pushed, popped);
    System.out.println(b);
  }

  public static boolean validateStackSequences(int[] pushed, int[] popped) {
    //辅助
    Stack<Integer> f = new Stack<Integer>();
    int cur = 0;
    for (int i = 0; i <= pushed.length - 1; i++) {
      f.push(pushed[i]);
      while (cur < popped.length && !f.isEmpty() && popped[cur] == f.peek()) {
        f.pop();
        cur++;
      }

    }
    return f.isEmpty();

  }

}
